﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BanXeTang
{
    public class Map : VisibleGameEntity
    {
        public override VisibleGameEntity Clone()
        {
            VisibleGameEntity newObject = new Map();
            newObject._sprite = this._sprite;
            newObject._nsprite = this._nsprite;
            newObject.X = this.X;
            newObject.Y = this.Y;

            return newObject;
        }

        public override bool Init(Microsoft.Xna.Framework.Content.ContentManager Content, int n, string strResource)
        {
            _nsprite = 1;
            _sprite = new MySprite[_nsprite];
            Texture2D[] texture2D;

            texture2D = new Texture2D[1];
            texture2D[0] = Content.Load<Texture2D>(@"Pictures/" + strResource);
            _sprite[0] = new MySprite(texture2D, X, Y);
            return true;
        }

        public override void Update(GameTime gameTime)
        {
            Input.keyboardState = Keyboard.GetState();
            

            if (Input.keyboardState.IsKeyDown(Keys.Down) && Math.Abs(GlobalSettings._DeltaY) + Game1.screenHeight < _sprite[0].texture2d[0].Height)
            {
                if (Game1.tankTa.Y + GlobalSettings._DeltaY > Game1.screenHeight / 3)
                    GlobalSettings._DeltaY = GlobalSettings._DeltaY - GlobalSettings.doDoi;
                if (Math.Abs(GlobalSettings._DeltaY) + Game1.screenHeight > _sprite[0].texture2d[0].Height)
                    GlobalSettings._DeltaY = Game1.screenHeight - _sprite[0].texture2d[0].Height;
                return;
            }
            if (Input.keyboardState.IsKeyDown(Keys.Up) && GlobalSettings._DeltaY < 0)
            {
                if (Game1.tankTa.Y + GlobalSettings._DeltaY <= Game1.screenHeight/3)
                    GlobalSettings._DeltaY = GlobalSettings._DeltaY + GlobalSettings.doDoi;
                if (GlobalSettings._DeltaY > 0)
                    GlobalSettings._DeltaY = 0;
                return;
            }
            if (Input.keyboardState.IsKeyDown(Keys.Left) && GlobalSettings._DeltaX < 0)
            {
                if (Game1.tankTa.X + GlobalSettings._DeltaX <= Game1.screenWidth/2)
                    GlobalSettings._DeltaX = GlobalSettings._DeltaX + GlobalSettings.doDoi;
                if (GlobalSettings._DeltaX > 0)
                    GlobalSettings._DeltaX = 0;
                return;
            }
            if (Input.keyboardState.IsKeyDown(Keys.Right) && Math.Abs(GlobalSettings._DeltaX) + Game1.screenWidth < _sprite[0].texture2d[0].Width)
            {
                if (Game1.tankTa.X + GlobalSettings._DeltaX > Game1.screenWidth / 2)
                GlobalSettings._DeltaX = GlobalSettings._DeltaX - GlobalSettings.doDoi;
                if (Math.Abs(GlobalSettings._DeltaX) + Game1.screenWidth > _sprite[0].texture2d[0].Width)
                    GlobalSettings._DeltaX = Game1.screenWidth - _sprite[0].texture2d[0].Width;
                return;
            }
           
        }
    }
}
